// LeftView.cpp : implementation of the CLeftView class
//

#include "stdafx.h"
#include "$$root$$.h"

#include "$$root$$Doc.h"
#include "LeftView.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLeftView

IMPLEMENT_DYNCREATE(CLeftView, CView)

BEGIN_MESSAGE_MAP(CLeftView, CView)
	//{{AFX_MSG_MAP(CLeftView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
	ON_BN_CLICKED(IDC_CAPT_BUTTON, OnCaptButton)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLeftView construction/destruction

CLeftView::CLeftView()
{
	// TODO: add construction code here

}

CLeftView::~CLeftView()
{
}

BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CLeftView drawing

void CLeftView::OnDraw(CDC* pDC)
{
	C$$Safe_root$$Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
}


/////////////////////////////////////////////////////////////////////////////
// CLeftView printing

BOOL CLeftView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CLeftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CLeftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CLeftView::OnInitialUpdate()
{
	CView::OnInitialUpdate();

	CMainFrame* pFrame = DYNAMIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
	CCJShellTree& treeCtrl = pFrame->GetLeftPane()->GetTreeCtrl();
	treeCtrl.TunnelTree(_T("C:\\"));
}

/////////////////////////////////////////////////////////////////////////////
// CLeftView diagnostics

#ifdef _DEBUG
void CLeftView::AssertValid() const
{
	CView::AssertValid();
}

void CLeftView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

C$$Safe_root$$Doc* CLeftView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(C$$Safe_root$$Doc)));
	return (C$$Safe_root$$Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CLeftView message handlers

int CLeftView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// Create the image list used by frame buttons.
	m_ImageList.Create( IDB_PUSHPIN, 16, 1, RGB( 255, 0, 255 ));

	// Create the caption.
	if (!m_Caption.Create(this, _T("Folder List")))
	{
		TRACE0(_T("Unable to create caption.\n"));
		return -1;
	}

	// Create the caption button.
	if (!m_CaptionButton.Create(NULL, WS_VISIBLE|BS_ICON|BS_OWNERDRAW|BS_CENTER|BS_VCENTER,
		CRect(0,0,0,0), this, IDC_CAPT_BUTTON))
	{
		TRACE0(_T("Unable to create caption button.\n"));
		return -1;
	}
	
	// set the caption buttons icon.
	m_CaptionButton.SetIcon( m_ImageList.ExtractIcon(2), CSize( 16, 15 ));
	
	if( !m_ShellTree.Create(WS_VISIBLE, CRect(0,0,0,0), this, IDC_SHELL_TREE))
	{
		TRACE0(_T("Unable to create tree control.\n"));
		return -1;
	}
	
	return 0;
}

void CLeftView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	if( m_Caption.GetSafeHwnd()) {
		m_Caption.MoveWindow( 0, 0, cx, 19 );
	}

	if( m_CaptionButton.GetSafeHwnd()) {
		m_CaptionButton.MoveWindow( cx-18, 2, 16, 15 );
	}

	if( m_ShellTree.GetSafeHwnd()) {
		m_ShellTree.MoveWindow( 0, 19, cx, cy-19 );
	}
}

CCJShellTree& CLeftView::GetTreeCtrl()
{
	return m_ShellTree;
}

void CLeftView::OnCaptButton()
{
	((CMainFrame*)AfxGetMainWnd())->SendMessage(WM_COMMAND, ID_VIEW_ALLFOLDERS);
}
